<!--
 * @Author: JiLin
 * @Date: 2023-04-09 11:05:08
 * @LastEditors: JiLin
 * @LastEditTime: 2023-04-09 18:06:32
 * @FilePath: \web\src\views\Home.vue
-->
<template>
	<div class="content">
		<stu-table v-loading="loading" :stuList="tableData" @refresh="getList"></stu-table>
	</div>
</template>
<script>
import StuTable from "@/components/StuTable";

import Cookie from "js-cookie";
import { Message } from "element-ui";
import axios from "axios";
export default {
	name: "Home",
	components: {
		StuTable,
	},
	data() {
		return {
			tableData: [],
			loading: true,
			loadingText: "加载中...",
		};
	},
	computed: {},
	watch: {},
	mounted() {
    this.getList()
  },
	methods: {
		getList() {
			let token = Cookie.get("token");
			const headers = {
				Authorization: token,
			};
			// 携带token
			axios
				.get("http://114.67.241.121:8088/stu/list", { headers: headers })
				.then(res => {
					if (res.data.code === 200) {
						Message.success("获取信息" + res.data.msg);
						console.log(res.data.data);
						this.tableData = res.data.data;
						setTimeout(() => {
							Message.warning("已过滤" + res.data.data.filter(i => !i.stuname).length + "条空值");
						}, 500);
					} else {
						Message.error(res.data.msg);
						this.$router.push({ name: "login" });
						Cookie.remove("token");
					}
				})
				.catch(err => {
					Message.warning(err);
				})
				.finally(() => {
					this.loading = false;
				});
		},
	},
};
</script>
<style lang="less" scoped>
.content {
	margin: 30px;
	padding: 20px;
	border: 1px solid #ccc;
	box-shadow: 1px 1px 3px #666;
}
</style>
